package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.NewDetailsServiceBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 对象详情  服务adapter
 * <p>
 * Created by Administrator on 2017/10/9.
 */

public class NewDetailsServiceAdapter extends RecyclerView.Adapter<NewDetailsServiceAdapter.NewDetailsServiceViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private List<NewDetailsServiceBean.Rows> mList;

    public NewDetailsServiceAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        mList = new ArrayList<>();
    }

    public void setData(List<NewDetailsServiceBean.Rows> mList){
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public NewDetailsServiceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_new_details_service, null);
        return new NewDetailsServiceViewHolder(view);
    }

    @Override
    public void onBindViewHolder(NewDetailsServiceViewHolder holder, int position) {
        NewDetailsServiceBean.Rows rows = mList.get(position);
        holder.tvProject.setText(rows.getContractName());//项目名称
        holder.tvService.setText(rows.getDetailName());//服务目录
        //周期规则 0：不限 1：年 2：季度 3:月 4：周 5：日 6：自定义范围
        if ("0".equals(rows.getCycle())) {
            holder.tvCycle.setText("不限");
        } else if ("1".equals(rows.getCycle())) {
            holder.tvCycle.setText("年");
        } else if ("2".equals(rows.getCycle())) {
            holder.tvCycle.setText("季度");
        } else if ("3".equals(rows.getCycle())) {
            holder.tvCycle.setText("月");
        } else if ("4".equals(rows.getCycle())) {
            holder.tvCycle.setText("周");
        } else if ("5".equals(rows.getCycle())) {
            holder.tvCycle.setText("日");
        } else if ("6".equals(rows.getCycle())) {
            holder.tvCycle.setText("自定义范围");
        }
        if ("1".equals(rows.getType())) {
            holder.tvCarried.setText(rows.getExecuteTimes() + "次");//执行次数
        } else if ("2".equals(rows.getType())) {
            holder.tvCarried.setText(rows.getExecuteTimes() + "人/天");//执行天数
        }

        holder.tvStart.setText(rows.getServiceStartDate());
        holder.tvEnd.setText(rows.getServiceEndDate());

        if ("1".equals(rows.getType())) {
            holder.tvSchedule.setText(rows.getCompleteTimes() + "次");//执行次数
        } else if ("2".equals(rows.getType())) {
            holder.tvSchedule.setText(rows.getCompleteTimes() + "人/天");//执行天数
        }
        //项目状态（0：待生效 1：已生效 2：已到期 3：缓存期 4：关闭）
        if ("0".equals(rows.getContractFlag())) {
            holder.tvStatus.setText("待生效");
        } else if ("1".equals(rows.getContractFlag())) {
            holder.tvStatus.setText("已生效");
        } else if ("2".equals(rows.getContractFlag())) {
            holder.tvStatus.setText("已到期");
        } else if ("3".equals(rows.getContractFlag())) {
            holder.tvStatus.setText("缓冲期");
        } else if ("4".equals(rows.getContractFlag())) {
            holder.tvStatus.setText("关闭");
        }

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    static class NewDetailsServiceViewHolder extends RecyclerView.ViewHolder {

        private View itemView;
        private TextView tvProject;
        private TextView tvService;
        private TextView tvCycle;
        private TextView tvCarried;
        private TextView tvStart;
        private TextView tvEnd;
        private TextView tvSchedule;
        private TextView tvStatus;

        public NewDetailsServiceViewHolder(View view) {
            super(view);
            itemView = view;
            tvProject = view.findViewById(R.id.tv_project);
            tvService = view.findViewById(R.id.tv_service);
            tvCycle = view.findViewById(R.id.tv_cycle);
            tvCarried = view.findViewById(R.id.tv_carried);
            tvStart = view.findViewById(R.id.tv_start);
            tvEnd = view.findViewById(R.id.tv_end);
            tvSchedule = view.findViewById(R.id.tv_schedule);
            tvStatus = view.findViewById(R.id.tv_status);
        }
    }
}
